package ilarele.planner.Project;

import ilarele.planner.Constants.ConstantValues;

import java.util.ArrayList;
import java.util.Calendar;


public class Project
{
	// Duration units
	public static final int DURATION_DAYS = 0;
	public static final int DURATION_WEEKS = 1;
	public static final int DURATION_MONTHS = 2;
	
	private static final int SIZE_DAYS = 56;
	private static final int SIZE_WEEKS = 15;
	private static final int SIZE_MONTHS = 4;

	private ArrayList<Task> all_tasks;
	private Calendar start_date;
	private Calendar finish_date;
	private int time_units;
	private int duration;

	public Project()
	{
		this.all_tasks = new ArrayList<Task>();
		this.time_units = DURATION_DAYS;
		this.start_date = ConstantValues.getTodayCalendar();
		this.start_date.set(110, 9, 1);
		this.finish_date = ConstantValues.getTodayCalendar();
		this.finish_date.set(110, 9, 1);
		this.duration = 0;
	}

	public void setAllTasks(ArrayList<Task> all_tasks)
	{
		this.all_tasks = all_tasks;
	}

	public ArrayList<Task> getAllTasks()
	{
		return all_tasks;
	}

	public int getDaySize()
	{
		switch (time_units)
		{
		case DURATION_DAYS:
			return SIZE_DAYS;
		case DURATION_WEEKS:
			return SIZE_WEEKS;
		case DURATION_MONTHS:
			return SIZE_MONTHS;
		default:
			return SIZE_DAYS;
		}
	}

	public int getPadding(Calendar task_start)
	{
		int days_diff = ConstantValues.getDiff(task_start, start_date);
		return days_diff * getDaySize();
	}

	public Calendar getStartDate()
	{
		return start_date;
	}

	public void setStartDate(Calendar startDate)
	{
		start_date = startDate;
	}

	public Calendar getFinishDate()
	{
		return finish_date;
	}

	public void setFinishDate(Calendar finishDate)
	{
		finish_date = finishDate;
	}

	public void addTask(Task new_dummy)
	{
		all_tasks.add(new_dummy);
		Calendar dummy_finish_date = new_dummy.getFinishDate();
		if (dummy_finish_date.after(finish_date))
		{
			// compute the duration
			duration = ConstantValues.getDiff(dummy_finish_date, start_date);
			ConstantValues.copyCalendar(dummy_finish_date, finish_date);
		}
	}
	
	public int getDuration()
	{
		return duration ;
	}
}
